package cn.bitkit.tools.data;


import cn.bitkit.base.util.StringUtil;

import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

/**
 * 
 * @author changbo
 *
 */
public class SignUtil {
	
	public static String getSignTextUntyped(Map<String, Object> map) {
		Map<String, String> stringMap = map.entrySet().stream()
				.collect(Collectors.toMap(Map.Entry::getKey, e -> StringUtil.toString(e.getValue())));
		return getSignText(stringMap);
	}
	
	/**
	 * 获取签名文本
	 */
	public static String getSignText(Map<String, String> map) {
		//使用TreeMap实现排序
        Map<String, String> treeMap = new TreeMap<>(map);
        return treeMap.entrySet().stream()
				.filter(e -> e.getKey()!=null && e.getValue()!=null)
				.map(e -> e.getKey() + "=" + e.getValue())
				.collect(Collectors.joining("&"));
	}
	
}
